home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / uupc.lzh / uupc / pcmail.c < prev    next >
C/C++ Source or Header  |  1990-01-16  |  19KB  |  742 lines

  1. /*
  2.  *    $Id: pcmail.c,v 1.4 90/01/16 10:26:55 crash Exp Locker: crash $
  3.  *
  4.  *    Copying and use of this program are controlled by the terms of the
  5.  *    Free Software Foundations GNU Emacs General Public License.
  6.  *
  7.  *    Copyright (C) 1987 Stuart Lynne
  8.  *    Version        0.1        March 31/1987
  9.  *
  10.  *    pcmail address1 address2 ... < the.message
  11.  *
  12.  *    DESCRIPTION
  13.  *
  14.  *    An 822 compatible (hopefully) mail delivery system for pc's.
  15.  *
  16.  *    Designed for delivering mail on a pc based system. It will put
  17.  *    local mail (ie, not @ or ! in address) into files in the default
  18.  *    mail directory.
  19.  *
  20.  *    If remote it will put into an outgoing mailbag in the default mail
  21.  *    directory. Performs a simple bundling of mail messages into one
  22.  *    file with arguments prepended as To: arg header lines. And adds a
  23.  *    Message-Lines: header which gives the number of lines in the
  24.  *    content part of the message (after the first blank line).
  25.  *
  26.  *        pcmail john jack jill@xyz.uucp < afile
  27.  *
  28.  *        To: john
  29.  *        To: jack
  30.  *        To: jill@xyz.uucp
  31.  *        X-Message-Lines: ?????
  32.  *        Content-Length: ?????
  33.  *
  34.  *        ...
  35.  *        ...
  36.  *        ...
  37.  *
  38.  *    Content-Length: is used without X- prepended to be compatible with AT&T
  39.  *    Mail bundles. This is not 822 compatible per se, but is allowed.
  40.  *
  41.  *    It also adds the From and Date lines.  Subject: lines may be inserted
  42.  *    by placing them at the beginning of the message.
  43.  *
  44.  *    A Unix version should lock the /usr/mail/mailbag file.
  45.  *
  46.  *    Another program called rpcmail will unbundle the files created by
  47.  *    pcmail and deliver each message to the local rmail. So conceptually
  48.  *
  49.  *        (pcmail ..... < ...; pcmail .... < ...) | sz -> rz | rpcmail
  50.  *
  51.  *    would deliver remote messages intact.
  52.  *
  53.  *    ENVIRONMENT VARIABLES
  54.  *
  55.  *    The following environment variables are used:
  56.  *        MAILBOX        current user's mailbox,     "crash"
  57.  *        NAME        current user's name,         "Frank Edwards"
  58.  *        DOMAIN        domain of this machine,     "ckctpa.UUCP"
  59.  *        MAILDIR        where is mail kept,            ":usr/crash"
  60.  *
  61.  *    COMPILING
  62.  *
  63.  *    Compiled by itself it will operate as a standalone program. If the
  64.  *    compiler option:
  65.  *
  66.  *        -DNOMAIN
  67.  *
  68.  *    is used, it will compile as a routine:
  69.  *
  70.  *        pcmail (argc, argv)
  71.  *        char **argv;
  72.  *        int argc;
  73.  *
  74.  *    and can be used internally in other programs.
  75.  *
  76.  *    CUSTOMIZATION
  77.  *        PCMAIL        mailbag for remote mail
  78.  *        RMAIL        rmail
  79.  */
  80.  
  81. #define ORGANIZATION    "ComputerKnowledge Corp, Clearwater FL"
  82.  
  83. #ifndef lint
  84. static char RCSid[] = "$Id: pcmail.c,v 1.4 90/01/16 10:26:55 crash Exp Locker: crash $";
  85. #endif /* lint */
  86.  
  87. /*
  88. # ifdef NOMAIN
  89. #  include "dcp.h"
  90. # else
  91. */
  92. #  include <stdio.h>
  93. #  include "host.h"
  94. /*
  95. # endif
  96. */
  97.  
  98. #ifdef MSDOS
  99. #  define PC_FILENMS    1
  100. #else
  101. #  ifdef AMIGA
  102. #    define PC_FILENMS    1
  103. #    ifdef MCH_AMIGA
  104. #      include <functions.h>
  105. #    else
  106. #      include <proto/exec.h>
  107. #    endif
  108. #  endif
  109. #endif
  110.  
  111. FILE *FOPEN();
  112.  
  113. #define FORWARD        "Forward to"
  114. #define    SBUFSIZ        124
  115.  
  116. FILE *mailfile;
  117. FILE *tempfile;
  118.  
  119. char buf[BUFSIZ];
  120. char miscbuff[100];
  121. long lines = 0;
  122. long bytes = 0;
  123. long sequence = 0;
  124.  
  125. long tloc;
  126. char chartime[26];            /* current time in ASCII */
  127. char *thetime;
  128.  
  129. char tfilename[100];
  130. char mfilename[100];
  131. char mailsent[100];
  132.  
  133. int flag_rnews = FALSE;        /* Flag for news posting instead of email */
  134. int local = TRUE;
  135. char remotes[BUFSIZ];
  136. char uucp[] = "uucp";
  137.  
  138. extern char *getcwd();
  139. extern int chdir();
  140.  
  141. extern void *malloc();
  142. extern char *index();
  143. extern char *rindex();
  144. extern char *fgets();
  145. extern int fputs();
  146.  
  147. #ifdef NOMAIN
  148. #  ifdef RMAIL
  149. #    define main    rmail
  150. #  else
  151. #    define main    lmail
  152. #  endif
  153. #  define exit    return
  154.     extern int debuglevel;
  155. #else
  156.     int debuglevel;
  157. #endif
  158.  
  159. #ifndef RMAIL
  160. char    Subject[132] = "";
  161. #endif
  162.  
  163. char *progname;            /* Holder for argv[0] for error messages */
  164. char *mcurdir;
  165. char s_mcurdir[BUFSIZ];    /* current directory path (save malloc call) */
  166.  
  167. main(argc, argv)
  168. char *argv[];
  169. {
  170.     long position;
  171.     register int header = 1;
  172.     register int amount;
  173.  
  174.     register int argcount;
  175.     register char **argvec;
  176.     int remote;
  177.     int s1, s2;
  178.  
  179.     progname = argv[0];
  180.  
  181. #ifndef NOMAIN
  182.     /* get environment var's */
  183.     HOSTINIT;
  184.     loadenv();
  185.  
  186.      if (argc <= 1) {
  187.         fprintf( stderr, "Usage:  %s [-s subj] users\n", progname );
  188.         exit(1);
  189.     }
  190.     debuglevel = 1;
  191. #endif
  192.  
  193. #ifdef RMAIL
  194.     local = FALSE;
  195. #else
  196.     local = TRUE;
  197. #endif
  198.  
  199.     if ( debuglevel > 5 ) {
  200.         fprintf( stderr, "%s: argc %d ", progname, argc );
  201.         argcount = argc;
  202.         argvec = argv;
  203.         while (argcount--)
  204.             fprintf( stderr, " \"%s\"", *argvec++ );
  205.         fputc( '\n', stderr );
  206.  
  207.         tloc = time( (long *)NULL );
  208.         thetime = ctime(&tloc);
  209.         fprintf( stderr, "thetime: %s\n",thetime );
  210.     }
  211.  
  212. #ifdef PC_FILENMS
  213.      getcwd( s_mcurdir, sizeof(s_mcurdir) );
  214. #else
  215.     getcwd( s_mcurdir, 0 );
  216. #endif
  217.     chdir( spooldir );
  218.  
  219.     /* get sequence number */
  220.     mkfilename( tfilename, confdir, SFILENAME );
  221.  
  222.      if ( debuglevel > 4 )
  223.         fprintf( stderr, "%s: opening %s\n", progname, tfilename ); /* */
  224.  
  225.     tempfile = FOPEN( tfilename, "r", 't' );
  226.     if (tempfile != (FILE *)NULL) {
  227.         fscanf( tempfile, "%ld", &sequence );
  228.         fclose( tempfile );
  229.     } else {
  230.          fprintf( stderr,
  231.             "%s: can't find %s file, creating\n", progname, tfilename );
  232.          sequence = 1;    /* start at 1 */
  233.      }
  234.     /* update sequence number */
  235.     if ( debuglevel > 5 )
  236.         fprintf( stderr, "%s: new sequence # %ld\n", progname, sequence );
  237.  
  238.     tempfile = FOPEN( tfilename, "w", 't' );
  239.     if (tempfile != (FILE *)NULL) {
  240.         fprintf( tempfile, "%ld\n", sequence+1 );
  241.         fclose( tempfile );
  242.     }
  243.     s1 = sequence;
  244.     /* open a temporary file */
  245.     /* sprintf( tfilename, TFILENAME, sequence ); */
  246.  
  247. try_tmpfile_again:
  248.      sprintf( miscbuff, TFILENAME, sequence );
  249.      mkfilename( tfilename, tempdir, miscbuff );
  250.  
  251.      if ( debuglevel > 5 )
  252.          fprintf( stderr, "%s: opening %s\n", progname, tfilename );
  253.  
  254.     tempfile = FOPEN( tfilename, "w", 'b' );
  255.      if (tempfile == (FILE *)NULL)  {        /* got an error here somehow */
  256.         fprintf( stderr, "%s: can't open %s\n", progname, tfilename );
  257. #ifdef FJE
  258.         if (++sequence < s1 + 100)            /* Try more than once... */
  259.             goto try_tmpfile_again;
  260.         else
  261. #endif /* FJE */
  262.             exit(1);
  263.     }
  264.     /* copy stdin to tempfile, counting content lines and bytes */
  265. #ifndef RMAIL
  266.     if ( strcmp( argv[1], "-s" ) == SAME ) {
  267.         argv += 2;
  268.         argc -= 2;
  269.         if ( argc == 0 )
  270.             return( -1 );
  271.         strcpy( Subject, *argv );
  272.     }
  273. #  ifdef FJE        /* Interactive Subject: line prompt */
  274.     else if (isatty( fileno(stdin) )) {
  275.         fputs("Subject: ", stderr);
  276.         fflush(stderr);
  277.         gets( Subject );
  278.     }
  279.     if (argc==2 && !strnicmp(argv[1], "rnews", 6))    /* same as stricmp() */
  280.         flag_rnews = TRUE;        /* Posting an article instead of email */
  281. #  endif /* FJE */
  282. #endif /* !RMAIL */
  283.  
  284.     header = 1;
  285.     while (fgets( buf, sizeof(buf), stdin ) != (char *)NULL) {
  286.         if (header) {
  287.             char *tmp = buf;
  288.             while (isspace(*tmp)) tmp++;
  289.             if (strlen( tmp ) < 2) {
  290.                 header = 0;
  291.                 continue;
  292.             } else if (strchr( tmp, ':' ) == NULL) {
  293.                 header = 0;
  294.             } else
  295.                 header = storehdr( tmp );
  296.         }
  297.         if (!header) {
  298.             lines++;
  299.             bytes += strlen( buf );
  300.             fputs( buf, tempfile );
  301.         }
  302.     }
  303.     /* get signature */
  304. #ifndef RMAIL
  305. #ifdef FJE            /* Different .signature if posting an article */
  306.     mkfilename( mfilename, home, flag_rnews ? POSTFILE : SIGFILE );
  307. #else
  308.     mkfilename( mfilename, home, SIGFILE );
  309. #endif /* !FJE */
  310.  
  311.     if (debuglevel > 4)
  312.         fprintf( stderr, "%s: opening sigfile %s\n", progname, mfilename );
  313.     mailfile = FOPEN( mfilename, "r", 't' );
  314.     if (mailfile != (FILE *)NULL) {
  315.         fputs( "\n-----\n", tempfile );
  316.         bytes += 7;
  317.         while (fgets( buf, sizeof(buf), mailfile ) != (char *)NULL) {
  318.             lines++;
  319.             bytes += strlen( buf );
  320.             fputs( buf, tempfile );
  321.         }
  322.         fclose( mailfile );
  323.      }
  324. #endif /* !RMAIL */
  325.  
  326.      fclose( tempfile );
  327.     if ( debuglevel > 4 ) {
  328.         fprintf( stderr, "%s: stdin copied to tmp: %ld bytes %ld lines\n",
  329.                      progname, bytes, lines );
  330.          fprintf( stderr, "%s: args %d\n", progname, argc );
  331.     }
  332.     /*
  333.      *    loop on args, copying to appropriate postbox,
  334.      *    do remote only once
  335.      *    remote checking is done empirically, could be better
  336.      */
  337.     remotes[0] = '\0';
  338.     argcount = argc;
  339.     argvec = argv;
  340.  
  341.     while (--argcount > 0) {
  342.         argvec++;
  343.         if ( debuglevel > 5 )
  344.             fprintf( stderr,
  345.                 "%s: arg# %d %s\n", progname, argcount, *argvec );
  346.         if (index( *argvec, '!' ) || index( *argvec, '@' ) ||
  347.                                      index( *argvec, '%' )) {
  348.             if ( debuglevel > 5 )
  349.                 fprintf( stderr, "%s: send to remote\n", progname );
  350.  
  351.             s1 = strlen( remotes );
  352.             s2 = strlen( *argvec );
  353.  
  354.             /* can we cram one more address on line */
  355.             if ( s1 > 0 && (s1 + s2 + 1) > 128 ) {
  356.                 /* dump it then, too bad */
  357.                 sendone( argc, argv, remotes, TRUE );
  358.                 remotes[0] = '\0';
  359.             }
  360.             /* add *arvgvec to list of remotes */
  361.             strcat( remotes, " " );
  362.             strcat( remotes, *argvec );
  363.         } else {
  364.             if ( debuglevel > 5 )
  365.                 fprintf( stderr,
  366.                     "%s: calling sendone %s\n", progname, *argvec );
  367.             sendone( argc, argv, *argvec, flag_rnews );
  368.         }
  369.     }
  370.     /* dump remotes if necessary */
  371.     if ( strlen( remotes ) > 0 )
  372.         sendone( argc, argv, remotes, TRUE );
  373.  
  374. #ifndef RMAIL
  375. #ifdef FJE
  376.     if (!flag_rnews)        /* Only record if email, not a posting */
  377. #endif /* FJE */
  378.     {
  379.         mkfilename( mailsent, home, COPYFILE );
  380.         if ( debuglevel > 4 )
  381.            fprintf( stderr, "%s: copfile = %s\n", progname, mailsent );
  382.         sendone( argc, argv, mailsent, FALSE );
  383.     }
  384. #endif /* !RMAIL */
  385.     unlink( tfilename );
  386.     chdir( s_mcurdir );
  387.     exit(0);
  388. }
  389.  
  390. static struct _header {
  391.     char *hdr;                /* Header text */
  392.     char *text;                /* Text found in letter for this header */
  393. } headers[] = {
  394.     { "Path:",            NULL },
  395.     { "Newsgroups:",    NULL },
  396.     { "Followup-To:",    NULL },
  397.     { "Organization:",    NULL },
  398.     { "Summary:",        NULL },
  399.     { "Received:",        NULL },
  400.     { "From:",            NULL },
  401.     { "Date:",            NULL },
  402.     { "Subject:",        NULL },
  403.     { "Message-ID:",    NULL },
  404.     { NULL,                NULL }  };
  405.  
  406. #define H_PATH        0
  407. #define H_GRPS        1
  408. #define H_FOLL        2
  409. #define H_ORG        3
  410. #define H_SUMM        4
  411. #define H_FROM        5
  412. #define H_RECV        6
  413. #define H_DATE        7
  414. #define H_SUBJ        8
  415. #define H_MSG        9
  416.  
  417. static struct _header *findhdr(str)
  418. register char *str;
  419. {
  420.     register struct _header *hdr = headers;
  421.  
  422.     while (hdr->hdr && strcmp(hdr->hdr, str))
  423.         hdr++;
  424.     return( hdr->hdr ? hdr : (struct _header *) 0);
  425. }
  426.  
  427. static int storehdr(str)
  428. register char *str;
  429. {
  430.     char ch;
  431.     register char *tmp = index(str, ':');
  432.     register struct _header *hdr;
  433.  
  434.     ch = *++tmp;
  435.     *tmp++ = '\0';
  436.     if (hdr = findhdr(str)) {
  437.         while (isspace(*tmp)) tmp++;
  438.         if (hdr->text = (char *) malloc(strlen(tmp) + 1)) {
  439.             strcpy(*hdr, str);
  440.             return( TRUE );
  441.         }
  442.     }
  443.     tmp[-1] = ch;        /* Either header not found or malloc() failed */
  444.     return( FALSE );
  445. }
  446.  
  447. static char *saveprintf(fmt, args)
  448. char *fmt;
  449. int args;
  450. {
  451.     register char *mem;
  452.  
  453.     if (mem = (char *) malloc(512))
  454.         vsprintf(mem, fmt, &args);
  455.     return( mem );
  456. }
  457.  
  458. char fpat1[] = "%c.%.7s%04ld";
  459. char fpat2[] = "S %s %s %s - %s 0666 %s";
  460.  
  461. /*
  462.  *    sendone copies file plus headers to appropriate postbox
  463.  *
  464.  *    NB. we do headers here to allow flexibility later, for example
  465.  *    in being able to do bcc, per host service processing etc.
  466.  */
  467.  
  468. sendone( argc, argv, address, remote )
  469. char **argv;
  470. int argc;
  471. char *address;
  472. {
  473.     register char     *cp;
  474.     char    icfilename[32];        /* local C. copy file */
  475.     char    ixfilename[32];        /* local X. xqt file */
  476.     char    idfilename[32];        /* local D. data file */
  477.     char    rxfilename[32];        /* remote X. xqt file */
  478.     char    rdfilename[32];        /* remote D. data file */
  479.      char    tmfilename[32];        /* temporary storage */
  480. #ifdef PC_FILENMS
  481.      char    cixfilename[32];    /* canonical ixfilename */
  482.      char    cidfilename[32];    /* canonical idfilename */
  483. #endif
  484. #ifdef FJE            /* Print the headers from headers[] */
  485.     register struct _header *start;
  486. #endif /* FJE */
  487.  
  488.      if ( remote ) {
  489.          /* sprintf all required file names */
  490.         sprintf( tmfilename, fpat1, 'C', mailserv, sequence );
  491.         importpath( icfilename, tmfilename );
  492. #ifdef PC_FILENMS
  493.          sprintf( cidfilename, fpat1, 'D', mailserv, sequence );
  494.         importpath( idfilename, cidfilename );
  495.         sprintf( cixfilename, fpat1, 'D', nodename, sequence );
  496.          importpath( ixfilename, cixfilename );
  497. #else
  498.         sprintf( tmfilename, fpat1, 'D', mailserv, sequence );
  499.         importpath( idfilename, tmfilename );
  500.         sprintf( tmfilename, fpat1, 'D', nodename, sequence );
  501.         importpath( ixfilename, tmfilename );
  502. #endif
  503.         sprintf( rdfilename, fpat1, 'D', nodename, sequence );
  504.         sprintf( rxfilename, fpat1, 'X', nodename, sequence );
  505.      } else {
  506.         /* postbox file name */
  507.          if ( index( address, SEPCHAR ) == (char *)NULL )
  508.             mkfilename( idfilename, maildir, address );
  509.         else
  510.             strcpy( idfilename, address );    /* Can't get here, can it!? */
  511.     }
  512.     if ( debuglevel > 5 )
  513.          fprintf( stderr, "%s: sendone: %s\n", progname, idfilename );
  514.  
  515.      if (!remote) {
  516.         if ( debuglevel > 5 )
  517.            fprintf( stderr, "%s: sendone: check for remote\n", progname );
  518.  
  519.         /* check for forwarding */
  520.         if ( (mailfile = FOPEN( idfilename, "r", 'b' )) != (FILE *)NULL ) {
  521.             cp = fgets( buf, BUFSIZ, mailfile );
  522.             fclose( mailfile );
  523.             if (cp && !strncmp( buf, FORWARD, 10 )) {
  524.                 strcpy( buf, buf+11 );
  525.                 return( sendone( argc, argv, buf, FALSE ) );
  526.             }
  527.         }
  528.     }
  529.     /* open mailfile */
  530.     if ( (mailfile = FOPEN( idfilename, "a+", 'b' )) == (FILE *)NULL ) {
  531.         fprintf( stdout, "%s: cannot append to %s\n", progname, idfilename );
  532.         return( 0 );
  533.     }
  534.     if ( debuglevel > 5 )
  535.         fprintf( stderr, "%s: append to mailfile\n", progname );
  536.  
  537.     tloc = time( (long *)NULL );
  538.      (void) strcpy(thetime = chartime, ctime(&tloc));    /* our own copy */
  539.     thetime[strlen(thetime)-1] = '\0';                    /* remove '\n' */
  540.  
  541. #ifdef RMAIL
  542.     fprintf( mailfile, "From uucp %s", thetime );
  543.     fputc( '\012', mailfile );
  544.     fprintf(mailfile, "Received: by %s (%s) %s", domain, progname, thetime);
  545.     fputc( '\012', mailfile );
  546. #else /* !RMAIL */
  547. # ifdef FJE
  548.     if (flag_rnews) {
  549.         start = &headers[H_PATH];
  550.         if (!headers[H_PATH].text)
  551.             headers[H_PATH].text = nodename;
  552.         if (!headers[H_ORG].text)
  553.             headers[H_ORG].text = ORGANIZATION;
  554.         headers[H_RECV].text = NULL;
  555.     } else {
  556.         start = &headers[H_RECV];
  557.         headers[H_PATH].text = NULL;
  558.         headers[H_ORG].text = NULL;
  559.         if (!headers[H_RECV].text)
  560.             headers[H_RECV].text = saveprintf("Received: by %s (%s) %s\012",
  561.                 domain, progname, thetime);
  562.         fprintf( mailfile, "From %s %s", mailbox, thetime );
  563.         if (remote) fprintf( mailfile, " remote from %s", nodename );
  564.         fputc( '\012', mailfile );
  565.     }
  566.     if (!headers[H_FROM].text)
  567. #ifdef KLUDGE_FROM_LINE
  568.     /*
  569.      *    From: Frank J. Edwards <ckctpa!crash@boake2>\012",
  570.      *                    name, nodename, mailbox, mailserv
  571.      */
  572.         headers[H_FROM].text = saveprintf("%s <%s!%s@%s>\012",
  573.             name, nodename, mailbox, mailserv);
  574. #else /* !KLUDGE_FROM_LINE */
  575.     /*
  576.      *    From: %s <%s@%s>\012", name, mailbox, domain
  577.      */
  578.         headers[H_FROM].text = saveprintf("%s <%s@%s>\012",
  579.             name, mailbox, domain);
  580. #endif /* KLUDGE_FROM_LINE */
  581.     if (!headers[H_DATE].text)
  582.         headers[H_DATE].text = saveprintf("%s\012", thetime);
  583.     if (!headers[H_MSG].text)
  584.         headers[H_MSG].text = saveprintf("<%ld@%s>\012", sequence, domain );
  585.     if (!headers[H_SUBJ].text)
  586.         headers[H_SUBJ].text = Subject;
  587.     for ( ; start->hdr; start++)
  588.         if (start->text)
  589.             fprintf(mailfile, "%s %s\012", start->hdr, start->text);
  590.  
  591.     if (!flag_rnews) {
  592.         /* add To: headers */
  593.         while (--argc > 0)
  594.             fprintf( mailfile, "To: %s\012", *++argv );
  595.     }
  596. # else /* FJE */
  597.     fprintf( mailfile, "From %s %s", mailbox, thetime );
  598.     if ( remote )
  599.         fprintf( mailfile, " remote from %s", nodename );
  600.     fputc( '\012', mailfile );
  601.     fprintf( mailfile, "Received: by %s (%s) %s\012",
  602.         domain, progname, thetime);
  603.     fprintf( mailfile, "Date: %s\012", thetime );
  604.  
  605.     /*    "From: %s <%s@%s>\012", name, mailbox, domain    */
  606.     fprintf( mailfile, "From: %s <%s@%s>\012", name, mailbox, domain );
  607.     fprintf( mailfile, "Message-ID: <%ld@%s>\012", sequence, domain );
  608.  
  609.     /* add To: headers */
  610.     while (--argc > 0)
  611.         fprintf( mailfile, "To: %s\012", *++argv );
  612.     if ( strlen( Subject ) > 0 ) {
  613.         fprintf( mailfile, "Subject: %s", Subject );
  614.         fputc( '\012', mailfile );
  615.     }
  616. # endif /* !FJE */
  617. # ifdef PCMAIL
  618.     /* add Message-Lines: and Content-Length: headers */
  619.     fprintf( mailfile, "X-Message-Lines: %ld", lines );
  620.     fputc( '\012', mailfile );
  621.     fprintf( mailfile, "Content-Length: %ld", bytes );
  622.     fputc( '\012', mailfile );
  623. # endif /* PCMAIL */
  624.     fputc( '\012', mailfile );        /* Blank line between hdrs & message */
  625. #endif /* !RMAIL */
  626.  
  627.     /* copy tempfile to postbox file */
  628.     if (debuglevel > 4)
  629.         fprintf( stderr, "%s: copy tempfile %s to %s\n",
  630.             progname, tfilename, idfilename );
  631.     tempfile = FOPEN( tfilename, "r", 'b' );
  632.     if ( tempfile == (FILE *)NULL) {
  633.         fprintf( stdout, "%s: can't re-open %s\n", progname, tfilename );
  634.         return( 0 );
  635.     }
  636.     while (fgets( buf, 512, tempfile ) != (char *)NULL) {
  637.         if ( strncmp( buf, "From ", 5 ) == 0 )
  638.             fputc( '>', mailfile );
  639.         if (cp = index(buf, '\n'))
  640.             *cp = '\0';
  641.         fputs( buf, mailfile );
  642.         fputc( '\012', mailfile );
  643.      }
  644.     /* close files */
  645.     fclose( mailfile );
  646.     fclose( tempfile );
  647.  
  648.     /* all done unless going to remote via uucp */
  649.     /* must create the job control files */
  650.  
  651.     if ( remote ) {
  652.         /* create remote X xqt file */
  653.         mailfile = FOPEN( ixfilename, "w", 'b' );
  654.         if     (mailfile == (FILE *)NULL) {
  655.             fprintf( stdout,
  656.                 "%s: cannot append to %s\n", progname, ixfilename );
  657.             return( 0 );
  658.         }
  659.         fprintf( mailfile, "U %s %s\012", uucp, nodename );
  660.         fprintf( mailfile, "F %s\012", rdfilename );
  661.         fprintf( mailfile, "I %s\012", rdfilename );
  662.         cp = address;
  663. #ifdef FJE
  664.         while (*cp && isspace(*cp))
  665.             cp++;
  666. # if 0
  667.         if ( !strncmp(cp, mailserv, first = strlen(mailserv)) ) {
  668.             if ( cp[ first ] == '!' )
  669.                 cp += first + 1;
  670.         }
  671. # endif
  672. #endif /* FJE */
  673.         fprintf(mailfile, flag_rnews ? "C rnews\012" : "C rmail %s\012",cp);
  674.         fclose( mailfile );
  675.  
  676.         /* create local C copy file */
  677.         mailfile = FOPEN( icfilename, "w", 't' );
  678.         if     (mailfile == (FILE *)NULL) {
  679.             printf("%s: cannot append to %s\n", progname, icfilename );
  680.             return( 0 );
  681.         }
  682. #ifdef PC_FILENMS
  683.          fprintf( mailfile, fpat2, cidfilename, rdfilename,
  684.                      uucp, cidfilename, uucp );
  685.          fputc( '\012', mailfile );
  686.          fprintf( mailfile, fpat2, cixfilename, rxfilename,
  687.                      uucp, cixfilename, uucp );
  688.          fputc( '\012', mailfile );
  689. #else
  690.         fprintf( mailfile, fpat2, idfilename, rdfilename,
  691.                     uucp, idfilename, uucp );
  692.         fputc( '\012', mailfile );
  693.         fprintf( mailfile, fpat2, ixfilename, rxfilename,
  694.                     uucp, ixfilename, uucp );
  695.         fputc( '\012', mailfile );
  696. #endif /* !PC_FILENMS */
  697.         fclose( mailfile );
  698.     }
  699.     return( 1 );
  700. }
  701.  
  702. #ifndef AMIGA
  703. # ifdef RMAIL
  704. rnews(argc, argv)
  705. int argc;
  706. char *argv[];
  707. {
  708.     struct tm    *thetm;
  709.     char    filename[132];
  710.     char    format[128];
  711.     FILE     *f;
  712.     char    buf[BUFSIZ];
  713.  
  714.     static int count = 0;
  715.  
  716.     tloc    = time( (long *)NULL );
  717.     thetime = ctime(&tloc);
  718.     thetm   = localtime( &tloc );
  719.  
  720.     /* mkfilename( format, spooldir, NEWSDIR );    */
  721.     sprintf( filename, NEWSDIR,
  722.         thetm->tm_year % 100, thetm->tm_mon,
  723.         thetm->tm_mday, thetm->tm_hour,
  724.         thetm->tm_min,  thetm->tm_sec,  count
  725.         );
  726.  
  727.     count++;
  728.     if ( debuglevel > 5 )
  729.         fprintf( stderr, "rnews: %s\n", filename );
  730.  
  731.     if ( (f = FOPEN( filename, "w", 't' )) == (FILE *)NULL ) {
  732.         fprintf( stderr, "rnews: can't open %s %d\n", filename, errno );
  733.         return( -1 );
  734.     }
  735.     while ( fgets( buf, BUFSIZ, stdin ) != (char *)NULL )
  736.         fputs( buf, f );
  737.     fclose( f );
  738. }
  739. # endif /* RMAIL */
  740. #endif /* !AMIGA */
  741. /* !AMIGA */
  742.